package logic

import (
	"context"

	"jinrigaoping/rpc/sys/internal/model"
	"jinrigaoping/rpc/sys/internal/svc"
	"jinrigaoping/rpc/sys/sys"

	"github.com/zeromicro/go-zero/core/logx"
)

type SysMenuUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSysMenuUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SysMenuUpdateLogic {
	return &SysMenuUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SysMenuUpdateLogic) SysMenuUpdate(in *sys.SysMenuUpdateReq) (*sys.SysMenuUpdateRes, error) {

	var isHide int64 = 0
	if in.IsHide {
		isHide = 1
	}

	var isKeepAlive int64 = 0
	if in.IsKeepAlive {
		isKeepAlive = 1
	}

	var isAffix int64 = 0
	if in.IsAffix {
		isAffix = 1
	}

	var isLink int64 = 0
	if in.IsLink {
		isLink = 1
	}

	var isIframe int64 = 0
	if in.IsIframe {
		isIframe = 1
	}

	l.svcCtx.SysMenuModel.Update(l.ctx, &model.SysMenu{
		MenuId:      in.MenuId,
		ParentId:    in.ParentId,
		Name:        in.Name,
		Path:        in.Path,
		Component:   in.Component,
		MenuType:    in.MenuType,
		Icon:        in.Icon,
		MenuSort:    in.MenuSort,
		Redirect:    in.Redirect,
		Title:       in.Title,
		IsHide:      isHide,
		IsKeepAlive: isKeepAlive,
		IsAffix:     isAffix,
		IsLink:      isLink,
		IsIframe:    isIframe,
		LinkUrl:     in.LinkUrl,
	})

	return &sys.SysMenuUpdateRes{}, nil
}
